home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Pointers to Arrays (or not)
- Date: 7 Mar 1996 19:31:47 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4hndj3$mgj@dawn.mmm.com>
- References: <4hkbg9$cja@aphex.direct.ca>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- qjackson@direct.ca wrote:
- > Hello:
-
- > I've come across something that I'm wondering about.
-
- > I have a class, Foo, with a member that is a pointer to Bar, where Bar
- > can be either a single object of Bar, or an array of Bar, depending on
- > other semantics:
-
-
- > class Foo
- > {
-
- > Bar* pBar;
- > int barTab; // how many Bar's are pointed to be pBar
-
- > ~Foo (void);
-
- > };
-
- > I would have thought that I could kill pBar this way:
-
- > delete [] pBar;
-
- > but that crashes if pBar was instantiated thus:
-
- > pBar = new Bar;
-
- [destructor with switch case elided]
-
- > What am I missing?
-
- You are not missing anything. There is a new/delete for arrays, and a
- new/delete for single objects. The delete you use must match the new
- you use.
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-